#import "BindMobileController.h"
#import "PPTextfield.h"
#import "LoginUtils.h"
#import "BaseWebViewViewController.h"
#import "CodeViewController.h"
#import "LoginUtils.h"


@interface BindMobileController ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet PPTextfield *accountTF;
///登录按钮
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@end


@implementation BindMobileController

+ (instancetype)controller {
    return [[[self class] alloc] init];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.tag = 10086;
}


- (void)setUpSubViews {
    [self setAccountTF];
}


- (void)setAccountTF{
    self.view.backgroundColor = WHITECOLOR;
    
    UIView *accountTFLeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 46)];
    self.accountTF.leftView = accountTFLeftView;
    self.accountTF.leftViewMode = UITextFieldViewModeAlways;
    
    self.accountTF.delegate = self;
    self.accountTF.isPhoneNumber = YES;
    self.loginBtn.enabled = NO;
    self.loginBtn.alpha = 0.4;
    
    WeakSelf(self)
    self.accountTF.ppTextfieldTextChangedBlock = ^(PPTextfield *tf) {
        StrongSelf(weakSelf)
        if (tf.text.length == 0) {
            strongSelf.loginBtn.enabled = NO;
            strongSelf.loginBtn.alpha = 0.4;
        }
        else{
            strongSelf.loginBtn.enabled = YES;
            strongSelf.loginBtn.alpha = 1.0;
        }
    };
}


- (IBAction)goback:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark 登录点击
- (IBAction)loginClick:(id)sender {
    
    if ([Utils isEmpty:_accountTF.text]) {
        return [self mbShowToast:@"手机号不能为空"];
    }
    if (!_accountTF.text.hhe_isMobileNumber) {
        return [self mbShowToast:@"您输入手机号异常哦！"];
    }
    
    CodeViewController *codeCtr = [[CodeViewController alloc] init];
    codeCtr.wechatLogin = YES;
    codeCtr.telephone = self.accountTF.text;
    [self.navigationController pushViewController:codeCtr animated:YES];
}

@end
